<#assign resources="${rc.contextPath}/resources">
<#assign path="${rc.contextPath}">
<head>
<meta charset="UTF-8">
    <title>商品详情</title>	
    <script >
		var path='${path}';
	</script>
    
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="${resources}/css/common.css" type="text/css">
    <link href="${resources}/plugins/fontAwesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
      <link href="${resources}/css/orderDetail.css" rel="stylesheet" type="text/css">
          <link href="${resources}/plugins/swiper/3.3.1/swiper.min.css" rel="stylesheet" type="text/css">
      
     <#include "setwxshare.ftl"/>
</head>

<body style="height: 100%; background-color: #F0EFED;">
<div id="container">
    <div class="header">
        <a href="javascript:history.back(-1)" class="fa fa-angle-left"></a>
        <span>订单详情</span>
    </div>
    
    <#if (cart_list?size> 0)>
    <!--普通商品列表-->
    <div class="orderList" id="cart_list" >
       	<#list  cart_list as cart>
	        <h3>${cart.merchant.name}</h3>
	        <ul>
	        	<#list cart.list as cartItem>
		            <li>
		                <div class="goodsImg">
		                    <img src="${cartItem.goods.picurl}">
		                </div>
		                <div class="goodsName">${cartItem.goods.name}</div>
		                <div class="price">￥${cartItem.goods.price}</div>
		                <div class="num">x ${cartItem.amount}</div>
		            </li>
	            </#list>
	        </ul>
        </#list>
    </div>
	<#if memberAddress??>
    <!--收货地址-->
    <a href="${path}/manage/address/select?returnURL=/manage/commodityOrder/order/${marketId}" class="address" >
    	
	        <div><h3>收货地址</h3>
	        <div class="userMes">
	            <span>${memberAddress.name}</span>
	            <span>${memberAddress.telephone}</span>
	        </div>
	        <div class="ad">
	          		  ${memberAddress.address}${memberAddress.street}
	        </div>
			
	        <span class="fa fa-angle-right"></span>
	        </div>
       
    </a>
	 <#else>
 			 <a href="${path}/manage/address/select?returnURL=/manage/commodityOrder/order/${marketId}" class="address" >
    			请绑定收货地址
	        <span class="fa fa-angle-right"></span>
	        </a>
       
    </a>
         </#if>
	</#if>

 	<#if (cartPicked_list?size> 0)>
    <!--自提商品列表-->
    <div class="orderList" id="cartPicked_list">
        	<#list  cartPicked_list as cart>
	        <h3>${cart.merchant.name}</h3>
	        <ul>
	        	<#list cart.list as cartItem>
		            <li>
		                <div class="goodsImg">
		                    <img src="${cartItem.goods.picurl}">
		                </div>
		                <div class="goodsName">${cartItem.goods.name}</div>
		                <div class="price">￥${cartItem.goods.price}</div>
		                <div class="num">x ${cartItem.amount}</div>
		            </li>
	            </#list>
	        </ul>
        </#list>

    </div>

    <!--商品自提，选择地址-->
    <div class="selectAd">
        <h3 class="adBtn" >商品自提 <span class="fa fa-angle-down"></span></h3>
		<div class="adCon" >
        <div class="city">
            <label for="city">市</label>
            <select id="city" onchange="ajaxbusiness()" >
				<#list businessDistrictList as District>                	<option value="${District.id}">${District.name}</option>
                </#list>
            </select>
        </div>

        <div class="district">
            <label for="district">区</label>
            <select id="district" onchange="ajaxPicked()" >
            </select>
        </div>

        <div class="detailAd">
            <label for="detailAd">自提点</label>
            <select id="detailAd">
            </select>
        </div>
	</div>
    </div>
	</#if>
    <!--订单总价-->
    <div class="orderPrice">
        订单总价
       <#if activity??>(${activity})</#if>&nbsp;&nbsp;<span class="orderPrice" id= "total">￥${total}
    </div>

    <!--手机号-->
    <div class="userPhone">
    
      
      	<#if phone == null>
			     <a class="pullRight bind">绑定新号码<i class="fa fa-chevron-right"></i> </a>
		<#else>	
			  您的手机号<span>${phone}</span>
		</#if>
    </div>

    <button id="submit"  onclick="submitOrder()">提交订单</button>
</div>
    <input type="hidden" value="${phone}" id="telephone">
    <input type="hidden" id="couponRecord" value="0">
    <input type="hidden" value="${memberAddress.id}" id="addressid">
    
</body>

<script src="${resources}/plugins/jquery/2.2.2/jquery.min.js"></script>
<script src="${resources}/js/common.js"></script>
<script src="${resources}/js/payBill.js"></script>
<script type="text/javascript">

   $(".adBtn").on("click", function () {
        $(".adCon").slideToggle();
        $(".selectAd").find(".fa").toggleClass("fa-angle-down").toggleClass("fa-angle-right");
   });

	//优惠券方法
	function couponRecord(couponRecordId,usageAmount){
		$("#couponRecord").val(couponRecordId);
		$("#total").html("￥"+parseFloat(${vo.total}-usageAmount).toFixed(2)+"(优惠券抵消"+parseFloat(usageAmount).toFixed(2)+"元)");
		
	}
	$(function(){
		if($("#cartPicked_list").html()!=''){
			ajaxbusiness();
		}
		
	})
	
	function submitOrder(){
 		var addressid = $("#addressid").val();
 		var telephone = $("#telephone").val();

	  	if(telephone==""){
      		common.alert({content:"请绑定手机号码"});
         	return;
       	} 
       	if($("#cart_list ul").length>0){
	       	if(addressid==""){
	      		common.alert({content:"请绑定收货地址"});
	         	return;
	       	} 
       	}
       	if($("#cartPicked_list ul").length>0){
	       	//自提点ID
			var pickedId=$("#detailAd").val();	
	       	if(pickedId==0 || pickedId==undefined){
	       			common.alert({content:"请选择自提点"});
		         	return;
	       	}
       	}
       	
		
       	
		//优惠券ID
		var couponRecordId=$("#couponRecord").val();
		//地址ID
		var addressId=$("#addressid").val();
		
		var detailAdId=$("#detailAd").val();
		if(detailAdId==undefined){
			detailAdId=0;
		}
		$.ajax({
 	        url: "${path}/manage/commodityOrder/create",
 	        type: "post",
 	        data:{
 	        	"marketid":"${marketId}",
 	        	"addressid":addressId,
 	        	"couponRecordId":couponRecordId,
 	        	"paymode":"1",
 	        	"pickedId":detailAdId
 	        },
 	        success: function(data) {
 	        	if(data.code == "000"){
 	        		window.location.href="${path}/pay/"+data.result;
 	        	}else if(data.code == "300"){
 	        		common.alert({
					    dialog: true,
						content:data.msg
					})
 	        	}
 	        }
 	    });	
	}

	//查询子商圈
	function ajaxbusiness(){
		$("#district").html("");
		var districtId=$("#city").val();
		$.ajax({
				url:"${path}/manage/commodityOrder/getDistrict?districtId="+districtId,
				type:"post",
				async:false,
				success:function(data){
					var html="";
					if(data.result.length>0){
						
						for(var i=0;i<data.result.length;i++){
							html+="<option value='"+data.result[i].id+"'>"+data.result[i].name+"</option>";
						}
						$("#district").html(html);
					}
					
			}
		})
		ajaxPicked();
	}	
	
	//查询自提点
	function ajaxPicked(){
		var districtId=$("#district").val();
		$("#detailAd").html("");
		$.ajax({
				url:"${path}/manage/commodityOrder/getPicked?districtId="+districtId,
				type:"post",
				async:false,
				success:function(data){
					if(data.result.length>0){
						var html="";
						for(var i=0;i<data.result.length;i++){
							html+="<option value='"+data.result[i].id+"'>"+data.result[i].address+"</option>";
						}
						$("#detailAd").html(html);
					}
					
			}
		})
	}	



</script>


